﻿using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;

namespace NQueries.Utils
{
    /// <summary>
    /// Contains various extensions for the <see cref="PropertyInfo" /> class.
    /// </summary>
    internal static class PropertyInfoExtensions
    {
        /// <summary>
        /// Gets a value indicating if this is an id property.
        /// </summary>
        /// <param name="propertyInfo"></param>
        /// <returns></returns>
        [SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "Valid for PropertyInfos only")]
        public static bool IsPrimaryKey(this PropertyInfo propertyInfo)
        {
            Check.IsNotNull(propertyInfo, "propertyInfo");
            return propertyInfo.GetAttributeOf<KeyAttribute>() != null;
        }
    }
}